import 'package:chat/components/chat_user_list_item.dart';
import 'package:flutter/material.dart';

import '../models/chat_user.dart';

class ChatUserList extends StatefulWidget {
  const ChatUserList({Key? key}) : super(key: key);

  @override
  State<ChatUserList> createState() => _ChatUserListState();
}

class _ChatUserListState extends State<ChatUserList> {
  List<ChatUser> chatUsers = [
    ChatUser(
        nickname: "一路有我",
        lastMessage: "上次的那张图像再发一次给我好吗？",
        imgUrl: "images/user_image_1.jpg",
        time: "13:10:11"),
    ChatUser(
        nickname: "侠客",
        lastMessage: "我才从上海回来。",
        imgUrl: "images/user_image_2.jpg",
        time: "11:01:23"),
    ChatUser(
        nickname: "梦遥",
        lastMessage: "最可能的是那时我不在...",
        imgUrl: "images/user_image_3.jpg",
        time: "8:17:33"),
    ChatUser(
        nickname: "有问必答",
        lastMessage: "我约了几个朋友一块儿去。",
        imgUrl: "images/user_image_4.jpg",
        time: "8:10:15"),
    ChatUser(
        nickname: "风雨",
        lastMessage: "刚拿到一个项目...",
        imgUrl: "images/user_image_5.jpg",
        time: "昨天"),
    ChatUser(
        nickname: "云在平流层",
        lastMessage: "我到时候约他们。",
        imgUrl: "images/user_image_6.jpg",
        time: "昨天"),
    ChatUser(
        nickname: "欢欢欢乐",
        lastMessage: "我还有最后一门课程要学。",
        imgUrl: "images/user_image_7.jpg",
        time: "昨天"),
    ChatUser(
        nickname: "来日方长",
        lastMessage: "上个周末才去的，不想去了。",
        imgUrl: "images/user_image_8.jpg",
        time: "两天前"),
    ChatUser(
        nickname: "古树",
        lastMessage: "忙了一个月，项目刚完成。",
        imgUrl: "images/user_image_9.jpg",
        time: "两天前"),
    ChatUser(
        nickname: "逍遥游",
        lastMessage: "你要来吗？",
        imgUrl: "images/user_image_10.jpg",
        time: "两天前"),
  ];
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: SingleChildScrollView(
        physics: const BouncingScrollPhysics(),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.only(top: 16, left: 16, right: 16),
              child: TextField(
                decoration: InputDecoration(
                    hintText: "搜索...",
                    hintStyle: TextStyle(color: Colors.grey.shade400),
                    prefixIcon: Icon(Icons.search,
                        color: Colors.grey.shade400, size: 20),
                    filled: true,
                    fillColor: Colors.grey.shade100,
                    contentPadding: const EdgeInsets.all(8),
                    enabledBorder: OutlineInputBorder(
                        borderRadius:
                            const BorderRadius.all(Radius.circular(30)),
                        borderSide: BorderSide(color: Colors.grey.shade100))),
              ),
            ),
            ListView.builder(
              itemCount: chatUsers.length,
              shrinkWrap: true,
              padding: const EdgeInsets.only(top: 16,left:10, right: 10),
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: (context,index)=>ChatUserListItem(nickname: chatUsers[index].nickname, lastMessage: chatUsers[index].lastMessage, imgUrl: chatUsers[index].imgUrl, time: chatUsers[index].time,isMessageRead: (index == 0 || index == 3)?true:false,),
            )
          ],
        ),
      ),
    );
  }
}
